package game_engine.core;


import java.util.ArrayList;

public class EntityGroup {
	
	private ArrayList<Entity> entities;
	
	public EntityGroup() {
		entities = new ArrayList<Entity>();
	}
	
	public void addEntity(Entity e) {
		synchronized(entities) {
			entities.add(e);
		}
	}
	
	public boolean removeEntity(Entity e) {
		synchronized(entities) {
			return entities.remove(e);
		}
	}
	
	public void doAction(float tick) {
		synchronized(entities) {
			for(int i = 0;i<entities.size();i++)
				entities.get(i).doAction(tick);
		}
	}
	
	public ArrayList<Entity> getEntities() {
		return entities;
	}
	
	public void render() {
		synchronized(entities) {
			for(int i = 0;i<entities.size();i++)
				entities.get(i).render();
		}
	}
	
	public void moveEntities(long tick) {
		synchronized(entities) {
			for(int i = 0;i<entities.size();i++)
				entities.get(i).move(tick);
		}
	}
	
	public void cleanEntities() {
		synchronized(entities) {
			for(int i = 0;i<entities.size();i++)
				if(entities.get(i).isDead()){
					entities.remove(i);
					i--;
				}
		}
	}
	
	public void updateAnimation(long tick) {
		synchronized(entities) {
			for(int i = 0;i<entities.size();i++) {
				entities.get(i).updateAnimation(tick);				
			}				
		}
	}
	
	public void clearEntities() {
		synchronized(entities) {
			entities.clear();
		}
	}
}
